<?php
namespace Orm\WinningLog;

use Base\Exception\RmException;
class WinningLogClass extends \Base\BaseOrmObject{
    protected   $id,
				$user_id = 0,
				$memo = '', // 备注
				$coupon_type = 0,
				$type = 0, //0已中奖 1未中奖
				$coupon_id = 0,
				$coupon_code = '',
				$coupon_type_name = '',
				$is_del = 0,
				$insert_time = '',
				$update_time = '';
    const NO_WINNING = 1; //未中奖标识

    function __init($data)
    {
        parent::__init($data);
        $this->dformat($data);
    }

    private function dformat()
    {
    }

    public function loadById($id = 0)
    {
        $model = new \Orm\WinningLog\WinningLogModel();
        $data = $model->loadById($id);
        self::__init($data);
    }

    public function insert()
    {
        $this->checkNecessaryParam();
        $data = array(
            'user_id' => $this->user_id,
			'memo' => $this->memo,
			'coupon_type' => $this->coupon_type,
			'type' => $this->type,
			'coupon_id' => $this->coupon_id,
			'coupon_code' => $this->coupon_code,
			'coupon_type_name' => $this->coupon_type_name,
        );

        $model = new \Orm\WinningLog\WinningLogModel();
        $model->insert($data);
        $this->id = $model->getLastId();
    }

    public function update()
    {
        $this->checkNecessaryParam();
        $data = array(
            'user_id' => $this->user_id,
			'memo' => $this->memo,
			'coupon_type' => $this->coupon_type,
            'type' => $this->type,
			'coupon_id' => $this->coupon_id,
			'coupon_code' => $this->coupon_code,
			'coupon_type_name' => $this->coupon_type_name,
        );

        $model = new \Orm\WinningLog\WinningLogModel();
        $model->update($data, "`id` = {$this->id}");
    }

    public function delete($id)
    {
        $data = array('is_del'=>1);
        $model = new \Orm\WinningLog\WinningLogModel();
        $model->update($data, "`id` = {$id}");
    }

    private function checkNecessaryParam()
    {
    }
}